package cn.edu.dutir.corpus.ntcir;

import cn.edu.dutir.corpus.QueryFiled;
import cn.edu.dutir.corpus.TopicHandler;
import cn.edu.dutir.indri.query.IndriQuery;
import cn.edu.dutir.indri.query.Object2IndriQuery;
import cn.edu.dutir.utility.Constants;

public class Ntcir2IndirQuery extends
		Object2IndriQuery<NTCIRTopic> {

	private final QueryFiled mQueryField;

	public Ntcir2IndirQuery(QueryFiled queryFiled,
			TopicHandler<IndriQuery> indriHandler) {
		super(indriHandler);
		mQueryField = queryFiled;
	}

	public Ntcir2IndirQuery(TopicHandler<IndriQuery> indriHandler) {
		this(QueryFiled.TITLE, indriHandler);
	}

	@Override
	public IndriQuery indriQuery(NTCIRTopic topic) {
		int num = topic.num();
		StringBuffer sb = new StringBuffer(Constants.DEFAULT_BUFFER_SIZE);
		switch (mQueryField) {
		case TITLE:
			sb.append(topic.title());
			break;
		case DESC:
			sb.append(topic.description());
			break;
		case NARR:
			sb.append(topic.narrative());
			break;
		case TITLE_DESC:
			sb.append(topic.title());
			sb.append(Constants.DEFAULT_SEPARATOR_STRING);
			sb.append(topic.description());
			break;
		case TITLE_DESC_NARR:
			sb.append(topic.title());
			sb.append(Constants.DEFAULT_SEPARATOR_STRING);
			sb.append(topic.description());
			sb.append(Constants.DEFAULT_SEPARATOR_STRING);
			sb.append(topic.narrative());
			break;
		case DSEC_NARRA:
			sb.append(topic.description());
			sb.append(Constants.DEFAULT_SEPARATOR_STRING);
			sb.append(topic.narrative());
			break;
		default:
			String msg = "Unsupport query filed are found with QueryField = "
					+ mQueryField;
			throw new IllegalArgumentException(msg);
		}
		return new IndriQuery(num, sb.toString());
	}
}
